package io.renren.modules.project.controller;

import java.util.List;
import java.util.Map;

import io.renren.common.annotation.SysLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.project.entity.LineInfoEntity;
import io.renren.modules.project.service.LineInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author tony Liu
 * @email 
 * @date 2018-11-22 17:12:30
 */
@RestController
@RequestMapping("/project/lineinfo")
public class LineInfoController {
	@Autowired
	private LineInfoService lineInfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("project:lineinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<LineInfoEntity> lineInfoList = lineInfoService.queryList(query);
		int total = lineInfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(lineInfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("project:lineinfo:info")
	public R info(@PathVariable("id") String id){
		LineInfoEntity lineInfo = lineInfoService.queryObject(id);
		
		return R.ok().put("lineInfo", lineInfo);
	}
	
	/**
	 * 保存
	 */
	@SysLog("新增线路")
	@RequestMapping("/save")
	@RequiresPermissions("project:lineinfo:save")
	public R save(@RequestBody LineInfoEntity lineInfo){
		boolean isOk = lineInfoService.save(lineInfo);
		if (!isOk){
			return R.ok().put("code",1111);
		}
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@SysLog("修改线路")
	@RequestMapping("/update")
	@RequiresPermissions("project:lineinfo:update")
	public R update(@RequestBody LineInfoEntity lineInfo){
		boolean isOk = lineInfoService.update(lineInfo);
		if (!isOk){
			return R.ok().put("code",1111);
		}
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("project:lineinfo:delete")
	public R delete(@RequestBody String[] ids){
		lineInfoService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
